//
//  MapViewController.m
//  Autobusim
//
//  Created by Hezi Cohen on 11/18/08.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "MapViewViewController.h"
#import "LocationGetter.h"



@implementation MapViewViewController

/*
// Override initWithNibName:bundle: to load the view using a nib file then perform additional customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically.
- (void)loadView {
}
*/

- (IBAction) lookForLocation {
	if ([gpsIndicator isAnimating])
	{
		[gpsLocSearchButton setImage:[UIImage imageNamed:@"location.png"]];
		[gpsIndicator stopAnimating];
	}
	else
	{
		[gpsLocSearchButton setImage:[UIImage imageNamed:@"empty.png"]];
		[gpsIndicator startAnimating];
		
		LocationGetter *locationManager = [LocationGetter alloc];
		locationManager.main = self;
		[locationManager begin];
	}
}


// Implement viewDidLoad to do additional setup after loading the view.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	// this may seem useless, but is actually requierd for ib to recognize RMMapView
	[RMMapView class];
	
	// Center map on tel aviv for start
	CLLocationCoordinate2D newLocation;
	newLocation.latitude = 32.0872;
	newLocation.longitude = 34.78996;
	[[mapView contents] moveToLatLong:newLocation];
}

- (void)setCoordinate:(double)longitude latitude:(double)latitude {
	CLLocationCoordinate2D coordinate;
	coordinate.latitude = latitude;
	coordinate.longitude = longitude;
	
	RMMapView *map = ((MapViewViewController*)self)->mapView;
	[[map contents] moveToLatLong: coordinate];
		
	if ([gpsIndicator isAnimating])
	{
		[gpsLocSearchButton setImage:[UIImage imageNamed:@"location.png"]];
		[gpsIndicator stopAnimating];
		
		CGContextRef context = UIGraphicsGetCurrentContext();
		[UIView beginAnimations:nil context:context]; 
		[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
		[UIView setAnimationDuration:0.3]; 
		CGRect viewFrame = [lineDetailsView frame];

		[lineDetailsView setHidden:NO];
		
		[UIView commitAnimations];		
	}
	
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientation
    return (YES);//interfaceOrientation == (UIInterfaceOrientationPortrait));
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


- (void)dealloc {
    [super dealloc];
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrient
{
    [self.navigationController setNavigationBarHidden:UIInterfaceOrientationIsLandscape(self.interfaceOrientation) animated:true];
}



@end
